<?php
function pw($pw,$key){
	if ($pw&&$key) {
		$md5one = hash_hmac('md5', $pw, $key);
		$md5two = hash_hmac('md5',$md5one,'snow');
		$md5three = hash_hmac('md5',$md5one,'kise');

		//计算大小写
		$rule = str_split($md5three);
		$source = str_split($md5two);
		for($i=0;$i<=31;$i++){ 
			if(!is_numeric($source[$i])){
				$str ="sunlovesnow1990090127xykab";
				if(strpos($str,$rule[$i])){
					$source[$i] = strtoupper($source[$i]);
				}
			}
		}
		$code32 = implode('', $source);
		$code1 = substr($code32, 0,1);
		if(!is_numeric($code1)){
				$code16 = substr($code32, 0,16);
			}else{
				$code16 = "K" . substr($code32, 1,16);
			}
		return $code16;
	}
	return;
}
error_reporting(0);
echo pw('test','test');
?>